package com.pocket.insight.base.sql.constant;

import org.apache.commons.lang3.StringUtils;

/**
 * 描述：
 *
 * @author shuize
 * @create 2024/11/29
 */
public interface ConnectionConst {

    String PROPERTY_KEY_PREFIX  = "_id_";
    String DEFAULT_JDBC_VERSION = "default";
    String MAX_CONN_NUM         = buildSysPropertyKey("max_conn_num");
    String JDBC_JAR_PATH        = buildSysPropertyKey("jdbc_jar_path");
    String JDBC_DRIVER_NAME     = buildSysPropertyKey("jdbc_driver_name");
    String SET_AUTO_COMMIT      = buildSysPropertyKey("set_auto_commit");
    String READ_UNCOMMITTED     = "READ_UNCOMMITTED";
    String READ_COMMITTED       = "READ_COMMITTED";
    String REPEATABLE_READ      = "REPEATABLE_READ";
    String SERIALIZABLE         = "SERIALIZABLE";

    static String buildSysPropertyKey(String name) {
        return PROPERTY_KEY_PREFIX + name;
    }

    static int getIsolationLevel(String setting) {
        if (StringUtils.isBlank(setting)){
            return 0;
        }
        switch (setting) {
            case READ_UNCOMMITTED:
                return 1;
            case READ_COMMITTED:
                return 2;
            case REPEATABLE_READ:
                return 4;
            case SERIALIZABLE:
                return 8;
            default :
                return 0;
        }
    }
}
